package algorithm;

import java.util.LinkedList;
import java.util.Queue;

public class QueueMakeStackTest {
    public static void main(String[] args) {
        QueueMakeStack stack = new QueueMakeStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        while (!stack.isEmpty()) {
            Integer pop = stack.pop();
            System.out.println(pop);
        }
    }
}

class QueueMakeStack{
    Queue<Integer> q1 = new LinkedList<>();
    Queue<Integer> q2 = new LinkedList<>();

    public void push(Integer data) {
        q1.add(data);
    }

    /**
     * q1     1 2 3 4
     *
     * q2    1 2 3                    4
     *
     *
     *
     * @return
     */
    public Integer pop(){
        while (q1.size() > 1) {
            q2.add(q1.remove());
        }
        Integer res = q1.poll();
        while (!q2.isEmpty()) {
            q1.add(q2.remove());
        }
        return res;
    }

    public int size(){
        return q1.size() + q2.size();
    }

    public boolean isEmpty(){
        return q1.isEmpty() && q2.isEmpty();
    }
}
